function copySelector(element: HTMLElement) {
	// 生成选择器
	function generateSelector(el: HTMLElement): string {
		const tagName = el.tagName.toLowerCase();
		const className = el.className ? `.${el.className.replace(/\s+/g, ".")}` : "";
		const id = el.id ? `#${el.id}` : "";

		let attributeSelector = "";
		const attr = Array.from(el.attributes).find((attr) => attr.name !== "class" && attr.name !== "id");

		if (attr) {
			attributeSelector = attr.name ? `[${attr.name}="${attr.value}"]` : "";
		}

		if (el.parentNode !== document.body) {
			return `${generateSelector(el.parentNode as HTMLElement)} > ${tagName}${className}${id}${attributeSelector}`;
		} else {
			return `${tagName}${className}${id}${attributeSelector}`;
		}
	}

	// 复制到剪贴板
	async function copyToClipboard(text: string) {
		try {
			await navigator.clipboard.writeText(text);
			console.log("Selector copied to clipboard!");
		} catch (err) {
			console.error("Error copying to clipboard:", err);
		}
	}

	const selector = generateSelector(element);
	copyToClipboard(selector);
}
